package com.fjwt.gz.mgr.ctrl.agent;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fjwt.gz.core.model.ApiRes;
import com.fjwt.gz.db.dto.AgentScoreDTO;
import com.fjwt.gz.db.entity.AgentScoreEntity;
import com.fjwt.gz.db.vo.AgentScoreVO;
import com.fjwt.gz.mgr.ctrl.CommonCtrl;
import com.fjwt.gz.service.impl.AgentScoreService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 机构积分类别表
 */
@RestController
@Slf4j
@RequestMapping("/api/agent/score")
public class AgentScoreController extends CommonCtrl {

    @Autowired
    private AgentScoreService agentScoreService;

    /**
     * 查询机构积分类别分页列表
     * @return
     */
    @GetMapping
    public ApiRes page() {
        AgentScoreDTO agentScoreDTO = getObject(AgentScoreDTO.class);
        log.info("pc端查询机构积分类别分页列表接口，请求地址：/api/agent/score，请求参数：{}", JSONUtil.toJsonStr(agentScoreDTO));
        IPage<AgentScoreVO> page = agentScoreService.page(getIPage(), agentScoreDTO);
        log.info("pc端查询机构积分类别分页列表接口，请求地址：/api/agent/score，返回结果：{}", JSONUtil.toJsonStr(page));
        return ApiRes.page(page);
    }

    /**
     * 新增机构积分类别
     * @return
     */
    @PostMapping
    public ApiRes add() {
        AgentScoreDTO agentScoreDTO = getObject(AgentScoreDTO.class);
        log.info("pc端新增机构积分类别接口，请求地址：/api/agent/score，请求参数：{}", JSONUtil.toJsonStr(agentScoreDTO));
        agentScoreService.add(agentScoreDTO);

        return ApiRes.ok();
    }

    /**
     * 修改机构积分类别
     * @return
     */
    @PostMapping("/update")
    public ApiRes update() {
        AgentScoreDTO agentScoreDTO = getObject(AgentScoreDTO.class);
        log.info("pc端修改机构积分类别接口，请求地址：/api/agent/score/update，请求参数：{}", JSONUtil.toJsonStr(agentScoreDTO));
        agentScoreService.update(agentScoreDTO);
        return ApiRes.ok();
    }

    /**
     * 机构积分类别详情
     * @return
     */
    @PostMapping("/detail")
    public ApiRes detail() {
        AgentScoreDTO agentScoreDTO = getObject(AgentScoreDTO.class);
        log.info("pc端机构积分类别详情接口，请求地址：/api/agent/score/detail，请求参数：{}", JSONUtil.toJsonStr(agentScoreDTO));
        AgentScoreEntity detail = agentScoreService.detail(agentScoreDTO);
        log.info("pc端机构积分类别详情接口，请求地址：/api/agent/score/detail，返回结果：{}", JSONUtil.toJsonStr(detail));
        return ApiRes.ok(detail);
    }

}

